<?php 
namespace app\app\controller\v1;
use think\Model;
use app\app\util\OnlineUtils;
use app\app\model\Store;

class StoreController extends BaseController{

	/**
	 * [index 商户列表]
	 * @return [type] [description]
	 */
	public function index()
	{
		$user_id = OnlineUtils::getUserIdBySid();
		//分页
		if( input('get.page') && input('get.page') > 1 ) {
			$page = input('get.page');
		} else {
			$page = 1;
		}
		$store = new Store();
		$result = $store->getAll($page);
		return jsonReturn(200,'success',$result);		
	}


	/**
	 * [addStore 添加商户]
	 * @param [type] $[name] [description]
	 * @param [type] $[name] [description]
	 * @param [type] $[name] [description]
	 */
	public function addStore()
	{
		$user_id = OnlineUtils::getUserIdBySid();
		$store   = new Store();
		$data    = [
			'name'   => input('post.name'),
			'address' => input('post.address'),
			'description' => input('post.description'),
			'image'       => input('post.image'),
			'lgt'         => input('post.lgt'),
			'lat'         => input('post.lat'),
			'phone'       => input('post.phone')
		];
		$result = $this->validate($data,'Store');
			if(true !== $result){
			// 验证失败 输出错误信息
			return jsonReturn(402,$result);
		}
		$data['create_time'] = time();
		$store->save($data);
		$id = $store->id;
		return jsonReturn(200,'success',$id);
	}
}